<template>
  <div id="inventory_loc" style="height:100%" v-loading="loading">
    <v-tableTitle :btnConfig="btnConfig" @download="download" :downloading="downloading"></v-tableTitle>
    <GTable class="base-grid" :hasCheck="true" :hasIndex="false" :hasEdit="true" v-model="gridObj"
             :defaultColDef="defaultColDef" :highlightCurrentRow="false" :disabled="true" api="queryVibdetailListByLoc" :rules="rules"
             :otherHeight="80" :tmsShowFilter="true" :columnConfig="columnConfig"
             :extraColumns="extraColumns" :showSummary="false" :pagination="true"
              @selection-change="handleSelectionChange"
             @filter-changed="filterChanged" @cell-dblclick="cellDblclick" @grid-ready="agGridReady">
    </GTable>
  </div>
</template>

<script>
import baseMixin from "@/mixins/BaseMixin";
import agGridBaseMixin from "@/mixins/AgGridBaseMixin";

export default {
  name: "inventory_loc",
  mixins: [baseMixin, agGridBaseMixin],
  props: {
    inputData: {
      type: Object
    }
  },
  data() {
    return {
      title:this.$t('ex.inventory_loc'),
      filterParams:{},
      selectData:[],
      downloading:false,
      height: 0,
      columnConfig:{ menu_id: 66, menu_code:"vibdetail", menu_list_code:"InventoryLoc", },
      defaultColDef: {
      }
    };
  },
  computed: {
    btnConfig() {
        return [
            {label: this.$t('common.export'), certigier: !this.btnPermNameList.includes('WM06020802'), invalid: "download",loading:this.downloading},
        ]
    }
  },
  methods: {
    filterChanged(param){
      this.filterParams = param.api.getFilterModel()
    },
    handleSelectionChange(data){
      this.selectData = data
    },
    download(){
      const {menu_list_code:menuListCode,menu_code:menuCode} = this.columnConfig;
      const excelName = this.title;
      if(menuListCode&&menuCode&&excelName){
        let params = []
        if(!this._.isEmpty(this.filterParams)){
          let obj = {}
          Object.keys(this.filterParams).forEach(key => {
            obj[key] = this.filterParams[key].filter
          })
          params = [obj]
        }
        if(!this._.isEmpty(this.selectData)){
          params = this.selectData
        }
        this.downloading = true
        this.$download({menuCode,menuListCode,name:excelName},params).then(res => {
          this.downloading = false;
        }).finally(() => {
          this.downloading = false;
        })
      }
    },
    async getTableData(page, data) {
      this.$set(data, "pageNum", page);
      this.$set(data, "pageSize", this.pageSize);
      try {
        this.loading = true;
        let res = await this.$api.post(`/queryVibdetailListByLoc`, data);
        
          this.rowData = res.page.list;
          this.page = res.page.curpage;
          this.pageSize = res.page.pageSize;
          this.total = res.page.total;
        
      } catch (e) {
        this.$message.error(e);
      } finally {
        this.loading = false;
      }
    }
  },
  mounted() {
    this.height = this.getHeight(window,60);
    this.$store.commit("setSkip", {});
    this.$store.commit("setRouteId", "");
    this.$store.commit("setNewFlag", false);
    this.$store.commit("setRouteData", {});
    // this.getTableData(1, {});
  },
};
</script>

<style scoped>
#inventory_loc {
  width: 100%;
  height: 99%;
}
</style>
